package com.f2prateek.rx.preferences2;

import io.reactivex.annotations.NonNull;
import ohos.data.preferences.Preferences;

import java.util.Set;

import static java.util.Collections.unmodifiableSet;

final class StringSetAdapter implements RealPreference.Adapter<Set<String>> {
    static final StringSetAdapter INSTANCE = new StringSetAdapter();

    @NonNull
    @Override
    public Set<String> get(@NonNull String key,
                           @NonNull Preferences preferences, @NonNull Set<String> defaultValue) {
        return unmodifiableSet(preferences.getStringSet(key, defaultValue));
    }

    @Override
    public void set(@NonNull String key, @NonNull Set<String> value,
                    @NonNull Preferences editor) {
        editor.putStringSet(key, value);
    }
}
